package com.ijianji.module_play_video.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.Observer
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.fenghuajueli.libbasecoreui.listener.OnListClickListener
import com.fenghuajueli.libbasecoreui.utils.QuickClickUtils
import com.fenghuajueli.libbasecoreui.viewmodel.BaseViewModelFragment
import com.fenghuajueli.module_route.PlayVideoModuleRoute
import com.ijianji.module_play_video.R
import com.ijianji.module_play_video.adapter.VideoRecommendGridAdapter
import com.ijianji.module_play_video.databinding.FragmentPlayHistroyBinding
import com.ijianji.module_play_video.model.PlayVideoModel
import com.tik.module_function.extension.initGridVideoListAdapter

/**
 * 播放记录页面
 */
@Route(path = PlayVideoModuleRoute.FRAGMENT_VIDEO_PLAY_HISTORY)
class PlayHistoryFragment : BaseViewModelFragment<PlayVideoModel,FragmentPlayHistroyBinding>() {
    var videoListAdapter: VideoRecommendGridAdapter? = null

    override fun createViewModel(): PlayVideoModel {
       return PlayVideoModel()
    }

    override fun createViewBinding(): FragmentPlayHistroyBinding {
       return FragmentPlayHistroyBinding.inflate(layoutInflater)
    }

    override fun initView(containerView: View?) {
        videoListAdapter = binding.rvVideoListView.initGridVideoListAdapter(arrayListOf(), OnListClickListener { position, data ->
            //点击事件
            if (QuickClickUtils.isFastClick()) {
                return@OnListClickListener
            }
            ARouter.getInstance().build(PlayVideoModuleRoute.ACTIVITY_VIDEO_PLAY)
                    .withString("videoId", data.vid)
                    .withString("videoName", data.title)
                    .withString("playListId", data.pid)
                    .withString("recommendPid", "tx_0_0xr2q2jc5msrs1d")
                    .navigation()
        })
        model.playHistoryVideoListData.observe(this, Observer {
            if (videoListAdapter != null) {
                videoListAdapter?.refreshData(it)
            }
        })

    }

    override fun initData() {
        model.loadPlayHistoryList()
    }


}